package com.kaishengit.dao;

import java.sql.ResultSet;
import java.sql.SQLException;

import com.kaishengit.entity.User;
import com.kaishengit.util.DBHelp;
import com.kaishengit.util.RowMapper;

public class UserDao {
	DBHelp<User> db = new DBHelp<User>();
	
	public User findUserByNameAndPassword(String name,String password) {
		String sql = "SELECT id,`name`,`password` FROM t_user WHERE `name`=? AND `password`=?";
		return db.executeQueryForObject(sql, new UserRowMapper(),name,password);
	}
	
	
	private class UserRowMapper implements RowMapper<User> {

		public User mapRow(ResultSet rs) throws SQLException {
			User user = new User();
			user.setId(rs.getInt("id"));
			user.setUsername(rs.getString("name"));
			user.setPassword(rs.getString("password"));
			return user;
		
		}
		
	}
}